<template>
  <div id="app">
    <el-container>
      <el-header>
        <div class="header-content">
          <h1>港口堆存费管理系统</h1>
          <div class="user-info" v-if="userStore.token">
            <span>欢迎，{{ userStore.userInfo?.username }}</span>
            <el-button type="text" @click="handleLogout" style="color: white; margin-left: 10px;">
              退出登录
            </el-button>
          </div>
        </div>
      </el-header>
      <el-container v-if="userStore.token">
        <el-aside width="200px">
          <el-menu
              router
              default-active="/in"
              class="el-menu-vertical-demo"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b"
          >
            <el-menu-item index="/dashboard">
              <el-icon><DataAnalysis /></el-icon>
              <span>仪表盘</span>
            </el-menu-item>
            <el-menu-item index="/in">
              <el-icon><Box /></el-icon>
              <span>入库管理</span>
            </el-menu-item>
            <el-menu-item index="/out">
              <el-icon><Van /></el-icon>
              <span>出库管理</span>
            </el-menu-item>
            <el-menu-item index="/fee" v-if="userStore.userInfo?.role !== 'CUSTOMER'">
              <el-icon><Money /></el-icon>
              <span>费用管理</span>
            </el-menu-item>
            <el-menu-item index="/reports" v-if="userStore.userInfo?.role !== 'CUSTOMER'">
              <el-icon><DataAnalysis /></el-icon>
              <span>报表统计</span>
            </el-menu-item>
            <el-menu-item index="/settings" v-if="userStore.userInfo?.role !== 'CUSTOMER'">
              <el-icon><Setting /></el-icon>
              <span>系统设置</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
      <el-container v-else>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { ElMessageBox } from 'element-plus'
import {
  Box,
  Van,
  Money,
  DataAnalysis,
  Setting
} from '@element-plus/icons-vue'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()

const handleLogout = () => {
  ElMessageBox.confirm('确认退出登录?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    userStore.logout()
    router.push('/login')
  }).catch(() => {
    // 用户取消
  })
}
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

.el-header {
  background-color: #409eff;
  color: white;
  line-height: 60px;
  padding: 0 20px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.header-content h1 {
  margin: 0;
  font-size: 20px;
}

.user-info {
  display: flex;
  align-items: center;
}

.el-aside {
  background-color: #545c64;
  color: #fff;
  height: calc(100vh - 60px);
}

.el-main {
  padding: 20px;
}
</style>